package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface DishMapper {
    @Select("select count(*) from dish where category_id=#{categoryId}")
    Integer countByCategoryId(Long categoryId);


    /**
     * 新增菜品
     * @param dish
     */
    @AutoFill(OperationType.INSERT)
    void insert(Dish dish);

    @Select("select id from dish where name=#{name}")
    Long selectByName(String name);


    Page<DishVO> selectPage(DishPageQueryDTO dishPageQueryDTO);

    Integer countEnableStatus(List<Long> ids);

    void deleteBatch(List<Long> ids);

    @Select("select * from dish where id=#{id}")
    Dish selectById(Long id);

    @Select("select * from dish where category_id=#{categoryId}")
    List<Dish> selectByCategoryId(Long categoryId);

    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);

    @AutoFill(OperationType.UPDATE)
    @Update("update dish set status=#{status} where id=#{id}")
    void setStatus(Long id, Integer status);

    List<Dish> selectDishConditionBy(@Param("categoryId") Long categoryId, @Param("enable") Integer enable);
}
